/**
 * Created with JetBrains PhpStorm.
 * User: xx
 * Date: 14-5-26
 * Time: 下午3:15
 * To change this template use File | Settings | File Templates.
 * 第一个目录项的高为30px, 简单模式宽为30px
 * 一般宽度为168px 中间区域左边空出2px
 */
(function (xxMenu, $, undefined) {

    /**
     * 初始化
     * @param options
     */
    xxMenu.init = function (options) {
        if (typeof options == "string") {
            options = {"ajaxURL": options};
        }
        defaults = $.extend({}, defaults, options);
        db.$menu = $("#" + defaults.id); //目录的jquery对象
        db.$center = $("#" + defaults.centerId); //中间区的jquery对象

        _initData();
        _showHtml();

        if (defaults.mode == "folded") { //如果是收起状态，自动切换模式
            defaults.mode = "open";
            _changeMode();
        }

        this.reflash();
    }

    /**
     * 选中菜单
     * @param key 如果key为空，重新打开有选中菜单
     * @param flag true:执行点击动作
     */
    xxMenu.select = function (key, flag) {
        _clickNode(key, flag);
    }

    /**
     * 转化模式
     */
    xxMenu.changeMode = function () {
        _changeMode();
    }

    /**
     * 刷新
     */
    xxMenu.reflash = function () {
        if (defaults.mode == "open") {
            if (status.currentNode && status.openNode.code && status.currentNode.p != status.openNode.code) {
                _clickNode(status.currentNode.code);
            }
        }
        else if (defaults.mode == "folded") {
        }
    }

    /**
     * 初始化数据
     * 私有
     */
    var _initData = function () {
        $.ajax({
            type: "get",
            url: defaults.ajaxURL,
            data: "",
            async: false,
            success: function (info) {
                if (!info) {
                    return;
                }
                if (typeof info == "string") {
                    info = $.parseJSON(info);
                }

                $.each(info, function (index, item) {
                    var node = {
                        code: false,
                        title: false,
                        pinyin: false,
                        level: false,
                        subMenu: false,
                        href: false,
                        type: false
                    };//节点
                    var indexNode = {
                        code: false,
                        level: false,
                        p: false,
                        $self: false,
                        $sub: false,
                        $parent: false,
                        $floating: false, //浮动二级菜单
                        $fnode: false, //浮动二级菜单项
                        top: false //上坐标
                    }; //索引节点

                    indexNode.code = node.code = item.code;
                    node.title = item.title;
                    node.pinyin = item.pinyin;

                    indexNode.level = node.level = 1;
                    indexNode.p = '';
                    db.indexList[node.code] = indexNode; //加入索引列表

                    if (item.subs > 0) { //有子菜单
                        node.subMenu = {};
                        node.href = false;
                        node.type = "group";

                        $.each(item.subMenu, function (i, o) {
                            var subNode = {
                                code: false,
                                title: false,
                                pinyin: false,
                                level: false,
                                subMenu: false,
                                href: false,
                                type: false
                            };//节点
                            var subIndexNode = {
                                code: false,
                                level: false,
                                p: false,
                                $self: false,
                                $sub: false,
                                $parent: false,
                                $floating: false,
                                $fnode: false,
                                top: false
                            }; //索引节点
                            subIndexNode.code = subNode.code = o.code;
                            subNode.title = o.title;
                            subNode.pinyin = o.pinyin;
                            subNode.subMenu = false;
                            subNode.href = o.href;
                            subNode.type = "href";
                            subIndexNode.level = subNode.level = 2;

                            node.subMenu[o.code] = subNode;

                            subIndexNode.p = item.code;
                            db.indexList[o.code] = subIndexNode; //加入索引列表

                            _createGroupList(subNode);//增加索引

                        });
                    } else {
                        node.subMenu = false;
                        node.href = item.href;
                        node.type = "href";

                        _createGroupList(node);//增加索引
                    }

                    db.nodeList[node.code] = node;
                });
            }
        });
    }

    /**
     * 获取节点
     * 私有
     * @param key
     */
    var _selectNode = function (key) {
        if (typeof db.indexList[key] == "undefined") {
            return false;
        }

        var node = false;
        index = db.indexList[key];
        if (index.level > 1) {
            node = $.extend({}, index, db.nodeList[index.p].subMenu[index.code]);
        }
        else {
            node = $.extend({}, index, db.nodeList[index.code]);
        }

        return node;
    }

    /**
     * 显示html数据
     * 私有
     */
    var _showHtml = function () {
        var $home = $("#" + defaults.id);
        $home.empty().html("");//清空原有数据
        $home.addClass("g-menu f-usn");

        _createSearchHtml($home);
        _createMenuHtml($home);
        _createBackBtnHtml($home);
    };

    /**
     * 搜索栏
     * 私有
     */
    var _createSearchHtml = function ($home) {
        var $divSearch = $('<div class="search"></div>');
        var $openSearchTip = $('<div class="search-tip"></div>');
        $divSearch.append($openSearchTip);
        $home.append($divSearch);

        var $floating = $('<div class="search-floating"></div>');
        var $divInput = $('<div class="search-floating-title"></div>');
        var $floatingInput = $('<input type="text" class="search-floating-input"/>');
        var $searchTip = $('<div class="search-tip-back"></div>');
        $divInput.append($floatingInput);
        $divInput.append($searchTip);
        $floating.append($divInput);

        var $searchGroup = $('<div class="search-floating-group"></div>');
        $floating.append($searchGroup);

        $floatingInput.keyup(function () {
            _search($(this).val());
        });

        $divSearch.click(function () {
            if ($floating.is(":hidden")) { //还没显示
                if (defaults.mode == "open") {
                    var offset = $(this).offset();
                    $floating.css("left", "0px");
                    $floating.css("top", offset.top + "px");
                } else if (defaults.mode == "folded") {
                    var offset = $(this).offset();
                    $floating.css("left", (offset.left + 30) + "px");
                    $floating.css("top", offset.top + "px");
                }
                $floating.show();
                $openSearchTip.hide();
                $floatingInput.focus();
            }
            else {
                $floating.hide();
                $openSearchTip.show();
            }
        });
        $searchTip.click(function () {
            _closeSearchFloating();
        });

        db.$menu.append($floating);
        db.searcher.$floating = $floating;
        db.searcher.$tip = $openSearchTip;
        db.searcher.$searchGroup = $searchGroup;
        db.searcher.$floatingInput = $floatingInput;
    };

    /**
     * 菜单栏
     * 私有
     */
    var _createMenuHtml = function ($home) {
        var divHome = $('<div style="height: auto;" class="m-menu"></div>');
        var ulMain = $('<ul class="c-memu"></ul>');

        $.each(db.nodeList, function (index, node) {
            ulMain.append(_createMenuNode(node, false));
        });
        divHome.append(ulMain);
        $home.append(divHome);
    };

    var _createMenuNode = function (node, $parent) {
        var key = node.code;
        var $li = $('<li class="c-memu-node"></li>');
        var nodeItem = $('<div class="c-node-' + node.level + '"></div>');//id="' + key + '"
        nodeItem.append('<div class="tip"></div>');

        var title = node.title;
        if (node.level > 1) {
            if (defaults.displayModel == 1) { //title显示模式
                title = "[" + node.pinyin.charAt(0) + "]" + title;
            }
        }
        nodeItem.append('<div class="title">' + title + '</div>');

        nodeItem.mouseenter(function (e) {
            _mouseenterNode(key, e);
        }).mouseleave(function (e) {
                _mouseleaveNode(key, e);
            });
        db.indexList[key].$self = nodeItem;//加入索引
        $li.append(nodeItem);

        //有下级菜单
        if (node.type == 'group' && node.subMenu) {
            var subUL = $('<div class="c-submemu"></div>'); //二级目录

            var subFloating = $('<div class="floating"></div>');//浮动目录
            subFloating.append("<div class='title'>" + node.title + "</div>")//浮动目录
            $.each(node.subMenu, function (index, subnode) {
                subUL.append(_createMenuNode(subnode, nodeItem));

                //浮动目录项
                var floatingNode = $("<div class='node'></div>");

                var title = subnode.title;
                if (subnode.level > 1) {
                    if (defaults.displayModel == 1) { //title显示模式
                        title = "[" + subnode.pinyin.charAt(0) + "]" + title;
                    }
                }
                floatingNode.append(title);

                floatingNode.click(function () {
                    _clickNode(subnode.code, true);
                }).mouseenter(function (e) {
                        _mouseenterNode(subnode.code, e);
                    }).mouseleave(function (e) {
                        _mouseleaveNode(subnode.code, e);
                    });
                db.indexList[subnode.code].$fnode = floatingNode;//加入索引
                subFloating.append(floatingNode);
            });
            $li.append(subUL);
            db.indexList[key].$sub = subUL;//加入索引

            db.$menu.append(subFloating);
            subFloating.mouseleave(function () { // 鼠标移出，关闭浮动菜单
                _closeFloating();
            });
            db.indexList[key].$floating = subFloating;//浮动目录
        } else if (node.level > 1) {
            db.indexList[key].$parent = $parent;
        }
        nodeItem.click(function () {
            _clickNode(key, true);

            //定时器
            if (reflashTime) {
                clearTimeout(reflashTime);
                reflashTime = false;
            }
            reflashTime = setTimeout("xxMenu.reflash()", defaults.delaytime);
        });
        return $li;
    }

    /**
     * 鼠标移入
     * @param key
     * @param e
     * @private
     */
    var _mouseenterNode = function (key, e) {
        var node = _selectNode(key);
        if (!node) {
            return;
        }

        if (defaults.mode == "open") {//当前这展开模式
            node.$self.addClass('c-node-' + node.level + '-hover');
        }
        else if (defaults.mode == "folded") {//当前收起模式
            if (node.level == 1) { //处理一级菜单
                node.$self.addClass('c-node-' + node.level + '-hover');
                if (node.type == "group") {
                    _closeFloating();//关闭浮动层

                    //打开这一个菜单项
                    status.openNode = node;
                    _changeNodeStatus(status.openNode, 2);//展开
                }
            }
            else { //浮动二级菜单
                node.$fnode.addClass("node-hover");
            }
        }

    }

    /**
     * 鼠标移出
     * @param key
     * @param e
     * @private
     */
    var _mouseleaveNode = function (key, e) {
        var node = _selectNode(key);
        if (!node) {
            return;
        }

        if (defaults.mode == "open") {
            node.$self.removeClass('c-node-' + node.level + '-hover');
        }
        else if (defaults.mode == "folded") {
            if (node.level == 1 && node.type == "group") { //收起模式下的一级菜单
                var nodeTop = _getNodeTop(node); //获取top位子
                if (_checkOffset(_getNodeTop(node), e)) {
                    _closeFloating();//关闭浮动层
                }
                node.$self.removeClass('c-node-' + node.level + '-hover');
            }
            else if (node.level == 1 && node.type == "href") {
                node.$self.removeClass('c-node-' + node.level + '-hover');
            }
            else {
                node.$fnode.removeClass("node-hover");
            }
        }
    }


    /**
     * 处理单击事件
     * 私有
     * @param key
     * @param flag 是否操作
     * @private
     */
    var _clickNode = function (key, flag) {
        var node = _selectNode(key);
        if (!node) {
            return;
        }
        if (defaults.mode == "open") { //展开模式
            _clickNodeMOpen(node);
        }
        else if (defaults.mode == "folded") { //收起模式
            _clickNodeMFolded(node);
        }

        //执行点击动作
        if (flag && node.type == "href") {
            defaults.fun({'code': node.code, 'p': node.p, 'title': node.title, 'pinyin': node.pinyin, 'href': node.href});
        }

        //关闭search浮动
        _closeSearchFloating();
    };

    /**
     * 处理选中事件 ，包括点击和接口调用
     * @param node
     * @private
     */
    var _clickNodeMOpen = function (node) {
        if (node.level == 1 && node.type == "href") { //一级目录 且 是href
            //关闭上一个菜单项
            if (status.openNode.code != node.code) {
                _changeNodeStatus(status.openNode, 0);///还原状态
            }

            //设置打开这一个菜单项
            status.openNode = node;

            if (status.currentNode.code != node.code) {
                _changeNodeStatus(status.currentNode, 0);//还原状态
                if (status.currentNode.level > 1) {
                    _changeNodeStatus(_selectNode(status.currentNode.p), 0);//还原状态
                }

                status.currentNode = node; //当前选中项
                _changeNodeStatus(status.currentNode, 3);//当前选中项
            }
        }
        else if (node.level == 2 && node.type == "href") { //二级目录 且 href
            //关闭上一个菜单项,当调用接口直接打开一个子菜单时起作用
            if (status.openNode.code != node.p) {
                //鼠标操作不会到这里
                _changeNodeStatus(status.openNode, 0);///还原状态
            }

            //当前已有其它目录选中，且一级目录不是当前打开的目录, 将原一级目录置为未选中
            if (status.currentNode) {
                if (status.currentNode.level > 1 && status.currentNode.p != node.p) {
                    if (status.currentNode.$parent) {
                        _changeNodeStatus(_selectNode(status.currentNode.p), 0);///还原状态
                    }
                }
            }

            //如果父节还没有展开， 先展开（或当前展开的不是接口调用的二级菜单所在的一级菜单）
            if (!status.openNode || node.p != status.openNode.code) {
                _clickNode(node.p);
            }

            //打开这一个菜单项
            if (status.currentNode.code != node.code) {
                // _changeNodeStatus(status.currentNode, 0);
                if (status.currentNode.$self) {
                    _changeNodeStatus(status.currentNode, 0);////还原状态
                }

                status.currentNode = node; //当前选中项
                _changeNodeStatus(status.currentNode, 3);///当前选中项
            }
        }
        else if (node.level == 1 && node.type == "group") { //一级目录，且不是href
            //关闭上一个菜单项
            if (status.openNode) {
                var parentKey = false;
                if (status.currentNode) {
                    parentKey = (status.currentNode.level > 1) ? status.currentNode.p : status.currentNode.code;
                }
                if (status.openNode.code != parentKey) {
                    _changeNodeStatus(status.openNode, 0);//还原状态
                }
            }

            if (status.openNode.$sub) {
                status.openNode.$sub.hide();
            }

            //打开这一个菜单项
            status.openNode = node;
            _changeNodeStatus(status.openNode, 2);//展开
        }
        else {
        }
    }

    /**
     * 处理选中事件 ，包括点击和接口调用,鼠标移入时也可触发
     * @param node
     * @private
     */
    var _clickNodeMFolded = function (node) {
        if (node.level == 1 && node.type == "href") { //一级目录 且 是href
            //关闭上一个菜单项
            if (status.openNode.code != node.code) {
                _changeNodeStatus(status.openNode, 0);///还原状态
            }

            //设置打开这一个菜单项
            status.openNode = node;

            if (status.currentNode.code != node.code) {
                _changeNodeStatus(status.currentNode, 0);//还原状态
                if (status.currentNode.level > 1) {
                    _changeNodeStatus(_selectNode(status.currentNode.p), 0);//还原状态
                }

                status.currentNode = node; //当前选中项
                _changeNodeStatus(status.currentNode, 3);//当前选中项
            }

            _closeFloating();//关闭浮动层
        }
        else if (node.level == 2 && node.type == "href") { //二级目录 且 href
            //当前已有其它目录选中，且一级目录不是当前打开的目录, 将原一级目录置为未选中
            if (status.currentNode) {
                if (status.currentNode.level > 1 && status.currentNode.p != node.p) {
                    _changeNodeStatus(status.currentNode, 0);////还原状态
                    _changeNodeStatus(_selectNode(status.currentNode.p), 0);//还原上级菜单状态
                }
            }

            //打开这一个菜单项
            if (status.currentNode.code != node.code) {
                _changeNodeStatus(status.currentNode, 0);//

                status.currentNode = node; //当前选中项
                _changeNodeStatus(status.currentNode, 3);//选中
            }

            _closeFloating();//关闭浮动层
        }
        else if (node.level == 1 && node.type == "group") { //一级目录，且不是href
            if (status.openNode) {
                _closeFloating();//关闭浮动层
            } else {
                //打开浮动层
                status.openNode = node;
                _changeNodeStatus(status.openNode, 2);//展开
            }
        } else { //其它
        }
    }

    var _changeMode = function () {
        if (defaults.mode == "open") { //收起菜单
            db.$menu.width(defaults.minWidth);
            db.$center.css("margin-left", (defaults.minWidth + 1) + "px");
            db.backBtn.addClass("back-tip-folded");
            defaults.mode = "folded";

            //收起二级菜单
            if (status.openNode.$sub) {
                status.openNode.$sub.hide();
            }
        } else if (defaults.mode == "folded") {//展开菜单
            db.$menu.width(defaults.width);
            db.$center.css("margin-left", (defaults.width + 1) + "px");
            db.backBtn.removeClass("back-tip-folded");
            defaults.mode = "open";

            _closeFloating();


        } else {
        }

        //关闭search浮动
        _closeSearchFloating();

        //打开选中的二级菜单
        var ccode = status.currentNode.code;
        status.currentNode = false;
        _clickNode(ccode);

        /**************************************************/
            //处理当前打开窗口的列表


        defaults.changeModeFun(defaults.mode); //回调外部函数，处理菜单收起，打开事件
    }

    /**
     * 返回按钮
     * 私有
     */
    var _createBackBtnHtml = function ($home) {
        var $backTmp = $('<div id="back_btn" class="back"></div>');
        var $back = $('<div class="back-tip-open"></div>');
        $backTmp.append($back);
        $backTmp.click(function () {
            _changeMode();
        });
        db.backBtn = $back; //收起、打开按钮
        $home.append($backTmp);
    };

    /********************************************************************/
    /* 私有方法 */
    /**
     * 获取node的坐标，当没有缓存时，获取并缓存
     * @param node
     */
    var _getNodeTop = function (node) {
        if (!node.top) {//没有top值，计算一次，并记入到db
            var offset = node.$self.offset();
            node.top = offset.top;
            db.indexList[node.code].top = node.top;
        }

        return node.top;
    }

    /**
     * 判断是否要关闭浮动层
     * 使用e.pageY ,兼容滚动条问题
     * @param nodeTop
     * @param e
     * @returns {boolean}
     * @private
     */
    var _checkOffset = function (nodeTop, e) {
        if (e.pageY <= nodeTop || e.pageY >= (nodeTop + 30)) {
            return true;
        }
    }

    /**
     * 改变结点状态
     * @param node
     * @param status
     *   0：原始状态
     *   1：获取焦点
     *   2：展开
     *   3：选中
     * @private
     */
    var _changeNodeStatus = function (node, status) {
        switch (status) {
            case 1:
                break;
            case 2: //展开
                if (defaults.mode == "open" && node.$sub) {
                    node.$sub.show();
                }
                if (defaults.mode == "folded" && node.$floating) {
                    node.$floating.css("top", _getNodeTop(node) + "px");
                    node.$floating.show();
                }
                if (node.$self) {
                    node.$self.addClass('c-node-' + node.level + '-open');
                }
                break;
            case 3: //选中
                if (defaults.mode == "open") {//展开模式
                    node.$self.addClass('c-node-' + node.level + '-active');
                    if (node.level > 1) { //如果选中的是二级目录，默认操作二级目录为选中
                        _changeNodeStatus(_selectNode(node.p), 3);
                    }
                } else if (defaults.mode == "folded") {//收起模式
                    if (node.level == 1) {
                        if (node.$self) {
                            node.$self.addClass('c-node-' + node.level + '-active');
                        }
                        if (node.$floating) {
                            node.$floating.addClass('floating-hover');
                        }
                    }
                    else if (node.level > 1) { //浮动二级目录选中
                        node.$fnode.addClass("node-active");
                        _changeNodeStatus(_selectNode(node.p), 3);//处理父级目录
                    }
                }
                break;
            default ://0
                if (node.$sub) {
                    node.$sub.hide();
                }
                if (node.$self) {
                    if (node.$self.hasClass('c-node-' + node.level + '-open')) {
                        node.$self.removeClass('c-node-' + node.level + '-open');
                    }
                    if (node.$self.hasClass('c-node-' + node.level + '-active')) {
                        node.$self.removeClass('c-node-' + node.level + '-active');
                    }
                }
                if (node.$floating) {//浮动菜单背景
                    node.$floating.removeClass('floating-hover');
                }

                if (node.$fnode) { //浮动菜单项处理
                    node.$fnode.removeClass('node-active');
                }

        }
    }

    /**
     * 关闭浮动层
     * @private
     */
    var _closeFloating = function () {
        if (status.openNode) {
            //如果没有选中项
            if (!status.currentNode) {
                _changeNodeStatus(status.openNode, 0);
            }
            //如果选中项为一级目录，且不是当前目录
            else if (!status.currentNode.p && status.currentNode.code != status.openNode.code) {
                _changeNodeStatus(status.openNode, 0);
            }
            //如果选中项为二级目录，且不是当前目录
            else if (status.currentNode.p && status.currentNode.p != status.openNode.code) {
                _changeNodeStatus(status.openNode, 0);
            }

            //关闭浮动
            if (status.openNode.$floating) {
                status.openNode.$floating.hide();
            }
            status.openNode = false;
        }
    };

    /**
     * 关闭search浮动
     * @private
     */
    var _closeSearchFloating = function () {
        db.searcher.$floating.hide();
        db.searcher.$tip.show();

        db.searcher.$searchGroup.empty().html("");
        db.searcher.$floatingInput.val("");
    };

    /**
     * 创建search索引
     * @param node
     * @private
     */
    var _createGroupList = function (node) {
        var indexNode = node.pinyin + node.title + "=[" + node.code + "]";
        var fastIndex = node.pinyin.length > 0 ? node.pinyin[0] : false; //拼音的首字母
        db.groupList.all += indexNode;

        if (fastIndex !== false) {
            fastIndex = '' + fastIndex;

            if (!db.groupList[fastIndex]) {
                db.groupList[fastIndex] = "";
            }
            db.groupList[fastIndex] += node.code;
            db.groupList[fastIndex] += ",";
        }
    }

    /**
     * 搜索
     * @param key
     */
    var _search = function (key) {
        db.searcher.$searchGroup.empty().html('');
        if (!key) {
            return;
        }
        key = key.toUpperCase(); //转化为大字

        var dbTmp = false;
        if (key.length == 1) {//判断是否为首字母
            var str = /[_a-zA-Z0-9]/;
            if (str.test(key)) {
                dbTmp = db.groupList[key];
            }
        }
        if (dbTmp) { //走首字母索引
            var searchNodeList = dbTmp.split(",");

            $.each(searchNodeList, function (i, v) {
                _createSearchNode(v);
            });
        } else {
            dbTmp = db.groupList.all;
            //BCDS1菜单四1=[menu-0011]BCDS2菜单四2=[menu-0012]BCDS3菜单四3=[menu-0013]
            var p = 0, start = 0, pCodeEnd = 0;
            var searchNode = '';
            do {
                p = dbTmp.indexOf(key, start);
                if (p >= 0) {
                    start = p;
                    p = dbTmp.indexOf("=[", start);
                    pCodeEnd = dbTmp.indexOf("]", start);
                    if (p < pCodeEnd) { //有效查找 ，即找到的不是 [] 内的内容
                        p += 2; //跳过 =[
                        searchNode = dbTmp.substring(p, pCodeEnd);
                        start = pCodeEnd;

                        _createSearchNode(searchNode);
                    }
                    else {
                        start++;
                    }
                }
            } while (p >= 0)
        }


        //增加search结果事件
        $(".search-floating-node").click(function () {
            _closeSearchFloating();
            _clickNode($(this).attr("code"), true);
        }).mouseenter(function () {
                $(this).children(".title").css("width", "100px");
                $(this).children(".tip").css("width", "68px");
                $(this).addClass("search-floating-node-hover");
            }).mouseleave(function () {
                $(this).children(".title").css("width", "168px");
                $(this).children(".tip").css("width", "0px");
                $(this).removeClass("search-floating-node-hover");
            });
    }

    _createSearchNode = function (key) {
        var node = _selectNode(key);
        if (node) {
            var code = node.code;
            var title = node.title;
            var ptitle = node.title;
            if (node.p) {
                var pnode = _selectNode(node.p);
                ptitle = pnode.title;
            }
            var searchNode = $('<div class="search-floating-node" code="' + code + '"><div class="title">' + title + '</div><div class="tip">' + ptitle + '</div></div>');
            db.searcher.$searchGroup.append(searchNode);
        }
    }

    /********************************************************************/
    /* 私有属性 */

    /**
     * 默认属性
     */
    var defaults = {
        id: 'xx_menu', //目录对应的ID
        centerId: "center", //中间区ID
        ajaxURL: '', //ajax获取目录数据
        width: 168, //目录宽 170
        minWidth: 30, //小目录宽 30
        mode: 'open', // folded  菜单模式
        delaytime: 3000, //自动刷新定时时长30000
        displayModel: 1, //标题显示模式 0：只显示title 1：显示拼音首字+title
        fun: function (href) { //单击菜单项处理
            //  alert(href);
        },
        changeModeFun: function (op) { //folded:合起 open:打开
        }
    };

    /**
     * 当前状态
     */
    var status = {
        currentNode: false, //当前选中的node
        openNode: false, //当前展开的node
        floating: false //当前浮动的node
    };

    /**
     * 目录数据
     * nodeList: 目录的原始数据，树结构
     * groupList：
     * indexList： 目录数据 + html的数据集合，链表结构
     */
    var db = {
        nodeList: {},
        groupList: {"all": ""}, //搜索分组索引 indexNode结构为：拼音标题=[id]
        indexList: {},
        searcher: {
            "$tip": false,
            "$floating": false,
            "$searchGroup": false,
            "$floatingInput": false
        }, //搜索
        backBtn: false,
        $menu: false,
        $center: false
    };

    /**
     *  自动reflash定时器
     * @type {boolean}
     */
    var reflashTime = false;

}(window.xxMenu = window.xxMenu || {}, jQuery));
